from django.contrib import auth
from django.http import HttpResponseRedirect
from django.shortcuts import render_to_response
from django.template.context import RequestContext

def login(request):
    redirect_url = request.GET.get('next','')
    username = request.POST['username']
    password = request.POST['password']
    user = auth.authenticate(username=username, password=password)
    if user is not None and user.is_active:
        # Correct password, and the user is marked "active"
        auth.login(request, user)
        # Redirect to a success page.
        return render_to_response('login.html',{'next':redirect_url })
    else:
        # Show an error page
            return HttpResponseRedirect("/account/invalid/")


def home(request):
    return render_to_response('base.html',
    RequestContext(request)
    )

